<?php

abstract class AbstractReport {

    protected $StFileName;
    private $ItColumns;
    private $THead;
    private $TBody;
    private $TFoot;
    private $ItLine;

    public function __construct($StFileName, $ItColumns) {
        $this->ItColumns = $ItColumns;
        $this->StFileName = $StFileName . '_' . today();
        $this->ItLine = 1;
    }

    public function addTitle($StTitle) {
        $this->THead .= "<tr><th colspan=\"$this->ItColumns\">$StTitle</th></tr>";
    }

    public function addHeaders( $ArHeaders ) {
        $this->THead .= '<tr class="header">';
        $this->TFoot .= '<tr><td colspan="'.$this->ItColumns.'" class="subtitle">';
        foreach( $ArHeaders as $MxColumn ) {
            $StColumn = is_array($MxColumn) ? key($MxColumn) : $MxColumn;

            $this->THead .= "<td>{$StColumn}</td>";
            $this->TFoot .= is_array($MxColumn) ? "{$StColumn}: {$MxColumn[$StColumn]}; " : '';
        }
        $this->TFoot .= '</td></tr>';
        $this->THead .= '</tr>';
    }

    public function addLine( $ArLine ) {
        $StClassColor = $this->ItLine++ % 2 == 0 ? 'color1' : 'color2';
        $this->TBody .= '<tr class="'.$StClassColor.'">';
        foreach( $ArLine as $StColumn ) {
            $this->TBody .= "<td>$StColumn</td>";
        }
        $this->TBody .= '</tr>';
    }

    public function getContent() {
        $this->THead = '<thead>' . $this->THead . '</thead>';
        $this->TBody = '<tbody>' . $this->TBody . '</tbody>';
        $this->TFoot = '<tfoot>' . $this->TFoot . '</tfoot>';
        return '<table class="Report">'.$this->THead . $this->TBody . $this->TFoot . '</table>';
    }

}

?>
